package com.chenxi.vhr.controller.common;

import com.chenxi.vhr.bean.BaseDictNation;
import com.chenxi.vhr.bean.BaseDictPoliticsStatus;
import com.chenxi.vhr.bean.VhrJobLevel;
import com.chenxi.vhr.bean.VhrPosition;
import com.chenxi.vhr.bean.common.Result;
import com.chenxi.vhr.service.BaseDictNationService;
import com.chenxi.vhr.service.BaseDictPoliticsStatusService;
import com.chenxi.vhr.service.VhrJobLevelService;
import com.chenxi.vhr.service.VhrPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : zhangchenxi
 * @create : 2022-02-10
 **/
@RestController
@RequestMapping("/common/select")
public class CommonSelectController {

    @Autowired
    private BaseDictNationService nationService;

    @Autowired
    private BaseDictPoliticsStatusService politicsStatusService;

    @Autowired
    private VhrJobLevelService jobLevelService;

    @Autowired
    private VhrPositionService positionService;

    @GetMapping("{ComboCode}")
    public Result getSelectInitList(@PathVariable Integer ComboCode) {
        ArrayList<CommonSelectVo> selectList = new ArrayList<>();
        switch(ComboCode) {
            case 1001:
                // 民族
                List<BaseDictNation> nationList = nationService.list();
                nationList.forEach(po -> {
                    CommonSelectVo vo = new CommonSelectVo();
                    vo.setId(po.getId());
                    vo.setValue(po.getId());
                    vo.setLabel(po.getName());
                    selectList.add(vo);
                });
                break;
            case 1002:
                // 政治面貌
                List<BaseDictPoliticsStatus> politicsStatusList = politicsStatusService.list();
                politicsStatusList.forEach(po -> {
                    CommonSelectVo vo = new CommonSelectVo();
                    vo.setId(po.getId());
                    vo.setValue(po.getId());
                    vo.setLabel(po.getName());
                    selectList.add(vo);
                });
                break;
            case 1003:
                // 职称
                List<VhrJobLevel> jobLevelList = jobLevelService.list();
                jobLevelList.forEach(po -> {
                    CommonSelectVo vo = new CommonSelectVo();
                    vo.setId(po.getId());
                    vo.setValue(po.getId());
                    vo.setLabel(po.getName());
                    selectList.add(vo);
                });
                break;
            case 1004:
                // 职位
                List<VhrPosition> positionList = positionService.list();
                positionList.forEach(po -> {
                    CommonSelectVo vo = new CommonSelectVo();
                    vo.setId(po.getId());
                    vo.setValue(po.getId());
                    vo.setLabel(po.getName());
                    selectList.add(vo);
                });
                break;
        }
        return Result.ok("加载成功！", selectList);
    }
}
